<?php  
session_start();  
ob_start();  
require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php'); 
require_once('../connections/con_gl.php');
$area = $_GET['area'];
list($namaarea) = mysql_fetch_row(mysql_query("select area from gl_area where id='$area'"));  


  
?>  
<html xmlns="http://www.w3.org/1999/xhtml"> <!-- Bagian halaman HTML yang akan konvert -->  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />  
<title><?php echo $data['NIS']; ?></title>  
 
<body style="font-size: 15 pt">

<h3 align="center">STOK KENDARAAN CABANG</h3>

<table width="100%" border="0.1" cellspacing="2" cellpadding="3" align="center">
	<thead>
	<tr style="text-align:center;background-color:#eee">
		<th width="3%" rowspan="3">No.</th>
		<th  colspan="3" rowspan="3">Jenis Kendaraan</th>
		<?php 
		$str = "select id, area from gl_area ";
		if($area != '') $str .= " where id='$area' ";
		$str .= "order by area asc ";
		$query = mysql_query($str) or die (mysql_error());
		while(list($idarea, $namaarea) = mysql_fetch_row($query)){
		list($jmlcabang) = mysql_fetch_row(mysql_query("select count(*) from gl_gudang where area='$idarea'"));
		echo "<th colspan='".($jmlcabang*4)."'>$namaarea</th>";
		}
		?>
	</tr>
	<tr style="text-align:center;background-color:#eee">
		<?php 
		$str = "select id, area from gl_area ";
		if($area != '') $str .= " where id='$area' ";
		$str .= "order by area asc ";
		$query = mysql_query($str) or die (mysql_error());
		while(list($idarea, $namaarea) = mysql_fetch_row($query)){
			$qcb = mysql_query("select id, gudang from gl_gudang where area = '$idarea' order by gudang asc") or die (mysql_error());
			$jqcb = mysql_num_rows($qcb);
			if($jqcb=='0'){
			echo "<th align='center'>&nbsp;</th>";
			}else{
			while(list($idgudang, $namagudang) = mysql_fetch_row($qcb)){
			echo "<th align='center' colspan='4'>$namagudang</th>";
			}
			}
		}
		?>
	</tr>
	<tr style="text-align:center;background-color:#eee">
		<?php 
		$str = "select id, area from gl_area ";
		if($area != '') $str .= " where id='$area' ";
		$str .= "order by area asc ";
		$query = mysql_query($str) or die (mysql_error());
		while(list($idarea, $namaarea) = mysql_fetch_row($query)){
			$qcb = mysql_query("select id, gudang from gl_gudang where area = '$idarea' order by gudang asc") or die (mysql_error());
			$jqcb = mysql_num_rows($qcb);
			if($jqcb=='0'){
			echo "<th align='center'>&nbsp;</th>";
			}else{
			while(list($idgudang, $namagudang) = mysql_fetch_row($qcb)){
			echo "<th align='center'>CORP</th>";
			echo "<th align='center'>RTL</th>";
			echo "<th align='center'>Tugas Kantor</th>";
			echo "<th align='center'>UGC</th>";
			}
			}
		}
		?>
	</tr>
	
	</thead>
	
	<?php
	$str = "select distinct a.merk, b.merk, a.tipekendaraan, c.tipekendaraan, a.jeniskendaraan, d.jeniskendaraan from gl_masterkendaraan as a left join gl_merkkendaraan as b on (a.merk=b.id) left join gl_tipekendaraan as c on (a.tipekendaraan=c.id) inner join gl_jeniskendaraan as d on (a.jeniskendaraan=d.id) "; //echo $str;
	if($area!='') $str.=" where a.area='$area'"; 
	$str .= " order by a.merk asc "; //echo $str;
	$query = mysql_query($str) or die (mysql_error());
	//print_r($str);
	$no=1;
	
	
	while(list($idmerk, $merk, $idtipe, $tipe, $idjenis, $jenis) = mysql_fetch_row($query)){
	
	
	//echo $v;
	echo "<tbody>";
	echo "<tr>";
	echo "<td align='center'>$no.</td>";
	echo "<td align='center'>$merk</td>";
	echo "<td align='center'>$jenis</td>";
	echo "<td width='160' align='center'>$tipe</td>";
	$strsub = "select id, area from gl_area ";
	if($area != '') $strsub .= " where id='$area' ";
	$strsub .= "order by area asc ";
	$querysub = mysql_query($strsub) or die (mysql_error());
	
	while(list($idarea, $namaarea) = mysql_fetch_row($querysub)){
		
		$qcb = mysql_query("select id, gudang from gl_gudang where area = '$idarea' order by gudang asc") or die (mysql_error());
		$jqcb = mysql_num_rows($qcb);
		if($jqcb=='0'){
		echo "<th align='center'>&nbsp;</th>";
		}else{
		while(list($idgudang, $namagudang) = mysql_fetch_row($qcb)){
		$strsub2 = "select count(*) from gl_masterkendaraan where merk='$idmerk' and tipekendaraan='$idtipe' and jeniskendaraan='$idjenis' and unitstok='1' and cabang='$idgudang' ";
		if($area!='') $strsub2.=" and area='$area' ";
		list($jmlretail) = mysql_fetch_row(mysql_query($strsub2)); if($jmlretail==0) $jmlretail="";
		echo "<td align='center'>$jmlretail</td>";
		$strsub2 = "select count(*) from gl_masterkendaraan where merk='$idmerk' and tipekendaraan='$idtipe' and jeniskendaraan='$idjenis' and unitstok='2' and cabang='$idgudang'";
		if($area!='') $strsub2.=" and area='$area' ";
		list($jmlcorporate) = mysql_fetch_row(mysql_query($strsub2)); if($jmlcorporate==0) $jmlcorporate="";
		echo "<td align='center'>$jmlcorporate</td>";
		$strsub2 = "select count(*) from gl_masterkendaraan where merk='$idmerk' and tipekendaraan='$idtipe' and jeniskendaraan='$idjenis' and unitstok='3' and cabang='$idgudang' ";
		if($area!='') $strsub2.=" and area='$area' ";
		list($jmloperational) = mysql_fetch_row(mysql_query($strsub2)); if($jmloperational==0) $jmloperational="";
		echo "<td align='center'>$jmloperational</td>";
		$strsub2 = "select count(*) from gl_masterkendaraan where merk='$idmerk' and tipekendaraan='$idtipe' and jeniskendaraan='$idjenis' and unitstok='4' and cabang='$idgudang' ";
		if($area!='') $strsub2.=" and area='$area' ";
		list($jmlcargo) = mysql_fetch_row(mysql_query($strsub2)); if($jmlcargo==0) $jmlcargo="";
		echo "<td align='center'>$jmlcargo</td>";
		}
		}
		
		
	}
	
	echo "</tr>";
	echo "</tbody>";
	$no++;
	$v++;
	}
	?>
</table> 

</body>  
</html><!-- Akhir halaman HTML yang akan di konvert -->  
<?php  
$filename="Laporan Stok Kendaraan Cabang ".$area.".pdf"; //ubah untuk menentukan nama file pdf yang dihasilkan nantinya  
//==========================================================================================================  
//Copy dan paste langsung script dibawah ini,untuk mengetahui lebih jelas tentang fungsinya silahkan baca-baca tutorial tentang HTML2PDF  
//==========================================================================================================  
$content = ob_get_clean();  
$content = '<page style="font-family: freeserif">'.nl2br($content).'</page>';  
  
 try  
 {  
  $html2pdf = new HTML2PDF('L',array(450,300),'en', false, 'ISO-8859-15',array(5, 20, 5, 10));  
  $html2pdf->setDefaultFont('Arial'); 
	
  $html2pdf->writeHTML($content, isset($_GET['vuehtml']));  
  $html2pdf->Output($filename);  
 }  
 catch(HTML2PDF_exception $e) { echo $e; }  
?>  